import os
import sys
import re
def countFile(countfile,words):
    try:
        with open(countfile,"r",encoding="utf-8") as f:
            txt=f.read()
            cleaned_txt=re.sub(r"[^a-z\s]"," ",txt.lower())
            txt1=cleaned_txt.split()
            for x in txt1:
                words[x]=words.get(x,0)+1
    except Exception as e:
        print(e)
        return 0
result={}
lst=os.listdir('.')
for x in lst:
    if os.path.isfile(x):
        if x.lower().endswith(".txt") and x.lower().startswith("a"):
            countFile(x,result)
lst=list(result.items())
lst.sort()
with open(sys.argv[1],"w") as f:
    for x in lst:
        f.write(f"{x[0]}\t{x[1]}\n")
